import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yt_devops/components/app_bar/app_bar_widget.dart';
import 'package:yt_devops/components/brn/brn_bottom_button_panel.dart';
import 'package:yt_devops/pages/site/site_setting/siet_elec_price_setting/add_mains_electricity_price/views/effective_date_widgets.dart';
import 'package:yt_devops/pages/site/site_setting/siet_elec_price_setting/add_mains_electricity_price/views/item_tow_checkbox_widget.dart';
import 'package:yt_devops/pages/site/site_setting/siet_elec_price_setting/add_mains_electricity_price/views/mains_hours_set_widgets.dart';
import 'package:yt_devops/pages/site/site_setting/siet_elec_price_setting/elec_price_title_widget.dart';
import 'package:yt_devops/pages/site/site_setting/site_setting_base_info/widgets/item_widget.dart';
import 'package:yt_devops/resources/str_res_keys.dart';
import 'package:yt_devops/styles/styles.dart';
import 'add_mains_electricity_price_controller.dart';

class AddMainsElectricityPricePage
    extends GetView<AddMainsElectricityPriceController> {
  const AddMainsElectricityPricePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<AddMainsElectricityPriceController>(
      builder: (controller) => Scaffold(
      resizeToAvoidBottomInset: true,
      backgroundColor: Colour.backgroundColor,
      appBar: AppBarWidget.withRightActions(ResKey.newMarketPriceElePrice.tr),
      body: Container(

          child: Column(
            children: [
              Expanded(
                child: ListView(padding: EdgeInsets.zero, children: [
                  Container(
                    height: 10,
                    color: Colour.backgroundColor,
                  ),
            Container(
              clipBehavior: Clip.hardEdge,
              margin: const EdgeInsets.only(left: 16,right: 16),
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(8),
                color: Colors.white,
              ),
              child:Column(
                  children: [ElecPriceTitleWidget(controller.titleStringList[0]),
                  ItemWidget(controller.titleDetailList[0],
                      controller.ruleNameController,
                      unitString: controller.unitList[0],
                      titleColor: Colour.otherTextColor,
                      inputTextColor: Colour.mainTextColor,
                      titleFont: 14,
                      isRequired: true,
                      isCanEdit: true, textChangeCallBack: (str) {
                    controller.checkCommitStatus();
                  }),
                  ItemTowCheckboxWidget(
                      ResKey.siteSettingElectricityEffectiveStatus.tr,
                      ResKey.siteSettingEffective.tr,
                      ResKey.siteSettingUnEffective.tr,
                      controller.status, (index) {
                    controller.status = index;
                  },isRequired: true,),])),
                  Container(
                    height: 10,
                    color: Colour.backgroundColor,
                  ),
            Container(
              clipBehavior: Clip.hardEdge,
              margin: const EdgeInsets.only(left: 16,right: 16),
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(8),
                color: Colors.white,
              ),
              child:Column(
                  children: [ElecPriceTitleWidget(controller.titleStringList[1]),
                  ItemWidget(controller.titleDetailList[1],
                      controller.powerElementController,
                      unitString: controller.unitList[1],
                      titleColor: Colour.otherTextColor,
                      inputTextColor: Colour.mainTextColor,
                      titleFont: 14,
                      isCanEdit: true, textChangeCallBack: (str) {
                    controller.checkCommitStatus();
                  }),
                  ItemTowCheckboxWidget(
                    ResKey.siteSettingElectricityBaseBillType.tr,
                    ResKey.capacity.tr,
                    ResKey.demand.tr,
                    controller.electricityType,
                    (index) {
                      controller.electricityType = index;
                    },
                    isShowDivider: true,
                  ),
                  ItemWidget(controller.titleDetailList[2],
                      controller.maxCapacityController,
                      unitString: controller.unitList[2],
                      titleColor: Colour.otherTextColor,
                      inputTextColor: Colour.mainTextColor,
                      titleFont: 14,
                      isCanEdit: true, textChangeCallBack: (str) {
                    controller.checkCommitStatus();
                  }),
                  ItemWidget(controller.titleDetailList[3],
                      controller.needPriceController,
                      unitString: controller.unitList[3],
                      titleColor: Colour.otherTextColor,
                      inputTextColor: Colour.mainTextColor,
                      titleFont: 14,
                      isShowDivider: false,
                      isCanEdit: true, textChangeCallBack: (str) {
                    controller.checkCommitStatus();
                  })])),
                  Container(
                    height: 10,
                    color: Colour.backgroundColor,
                  ),
            Container(
              clipBehavior: Clip.hardEdge,
              margin: const EdgeInsets.only(left: 16,right: 16),
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(8),
                color: Colors.white,
              ),
              child:Column(
                  children: [ElecPriceTitleWidget(controller.titleStringList[2]),
                  ItemWidget(
                    controller.titleDetailList[4],
                    controller.maxPriceController,
                    unitString: controller.unitList[4],
                    titleColor: Colour.otherTextColor,
                    inputTextColor: Colour.mainTextColor,
                    titleFont: 14,
                    isCanEdit: true,
                  ),
                  ItemWidget(
                    controller.titleDetailList[5],
                    controller.peakPriceController,
                    unitString: controller.unitList[5],
                    titleColor: Colour.otherTextColor,
                    inputTextColor: Colour.mainTextColor,
                    titleFont: 14,
                    isCanEdit: true,
                  ),
                  ItemWidget(
                    controller.titleDetailList[6],
                    controller.averageProtectController,
                    unitString: controller.unitList[6],
                    titleColor: Colour.otherTextColor,
                    inputTextColor: Colour.mainTextColor,
                    titleFont: 14,
                    isCanEdit: true,
                  ),
                  ItemWidget(
                    controller.titleDetailList[7],
                    controller.valleyReleaseController,
                    unitString: controller.unitList[7],
                    titleColor: Colour.otherTextColor,
                    inputTextColor: Colour.mainTextColor,
                    titleFont: 14,
                    isCanEdit: true,
                  )])),
                  Container(
                    height: 10,
                    color: Colour.backgroundColor,
                  ),
                  EffectiveDateWidgets(controller.timeDateList, () {
                    controller.updateTimeList();
                  }, (index) {
                    controller.deleteTimeList(index);
                  }, () {
                    controller.update();
                  },isRequired: true,),
                  Container(
                    height: 10,
                    color: Colour.backgroundColor,
                  ),
                  MainsHoursSetWidgets(controller.peakAndPlateauList, () {
                    controller.updatePeakAndPlateauListList();
                  }, (index) {
                    controller.deletePeakAndPlateauListList(index);
                  }, () {
                    controller.update();
                  }, () {
                    controller.update();
                  }),
                  Container(
                    height: 10,
                    color: Colour.backgroundColor,
                  ),
                ]),
              ),
            ],
          ),
        ),
        bottomNavigationBar: Container(
          color: Colour.white,
          padding: EdgeInsets.only(bottom: ScreenUtil().bottomBarHeight),
          child: YtBrnBottomButtonPanel(
              enableMainButton: controller.isEnableCommit,
              mainButtonName: ResKey.save.tr,
              mainButtonOnTap: () => controller.save(),
              secondaryButtonName: ResKey.cancel.tr,
              enableSecondaryButton: true,
              secondaryButtonBorder:
              Border.all(color: Colour.dividerColor),
              secondaryButtonOnTap: () => controller.cancelEdit()),
        ),
      ),
    );
  }

  
}
